package com.crm.controller;

import com.crm.dto.ClueGainDto;
import com.crm.entity.Clue;
import com.crm.result.*;
import com.crm.service.ClueService;
import com.crm.service.IDeptService;
import com.crm.vo.ClueANDFollowVo;
import com.crm.vo.DeptTreeVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 线索管理相关接口
 */
@RestController
public class ClueController{
    @Autowired
    ClueService clueService;
    @Autowired
    IDeptService deptService;

    /**
     * 新建线索
     * @param clue
     */
    @PostMapping("/clues/clue")
    public Result insertClue(@RequestBody Clue clue){
        clueService.insertClue(clue);
//        System.out.println(clue);
        return Result.success();
    }
    /**
     * 分页查询线索列表
     */
    @GetMapping("/clues/clue/list")
    public PageResultTow getClueList(@ModelAttribute CluePage cluePage) {
        PageResultTow clueListByPage = clueService.getClueListByPage(cluePage);
        return clueListByPage;
    }

//    /**
//     * http://localhost:8888/api/system/notice/list/0
//     * @return
//     */
//    @GetMapping("/system/notice/list/{transfer}")
//    public PageResultTow getClueList0(@PathVariable Integer transfer) {
//        PageResultTow clueListByPage = clueService.getClueListByPage(cluePage);
//        return clueListByPage;
//    }

    /**
     * 根据id查询回显
     */
    //clues/record/list?clueId=9183
    @GetMapping("/clues/clue/{clueId}")
    public Result<ClueANDFollowVo> getClueById(@PathVariable Long clueId) {
        ClueANDFollowVo clueById = clueService.getClueById(clueId);
//        return clueService.getClueById(clueId);
        return Result.success(clueById);
    }

    /**
     * 分配功能查询部门列表
     */
    @GetMapping("/system/dept/treeselect")
    public Result<List<DeptTreeVo>> getDeptTreeSelect() {
        List<DeptTreeVo> deptTreeList = deptService.getDeptTreeList();
        return Result.success(deptTreeList);
    }
    /**
     * http://localhost:8888/api/system/user/listselect?deptId=103
     * 根据部门查询用户
     */
//    @GetMapping("/system/user/listselect")
//    public Result<List<DeptTreeVo>> getUserListSelect(@RequestParam Integer deptId) {
//        List<DeptTreeVo> userListSelect = clueService.getUserListSelect(deptId);
//        return Result.success(userListSelect);
//    }

    /**
     * 批量分配功能
     */
    @PutMapping("/clues/clue/assignment")
    public Result putAssignment(@RequestBody ClueGainDto clueGainDto){
        clueService.putAssignment(clueGainDto);
        return Result.success();
    }


}
